﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace PasswordControl.UI.WPF.ViewModel
{
    abstract class ViewModelBase : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged<ReturnType>(Expression<Func<ViewModelBase, ReturnType>> propertyExpr)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new System.ComponentModel.PropertyChangedEventArgs(GetPropertySymbol(propertyExpr)));
            }
        }

        protected string GetPropertySymbol<ParameterType, ReturnType>(Expression<Func<ParameterType, ReturnType>> expression)
        {
            return ((MemberExpression)expression.Body).Member.Name;
        }

        #endregion
    }
}
